home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / MAP Viewer / Face.h < prev    next >
C/C++ Source or Header  |  2003-10-09  |  5KB  |  243 lines

  1. /*
  2. Half-Life MAP viewing utility.
  3. Copyright (C) 2003  Ryan Samuel Gregg
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #pragma once
  21. #include "stdafx.h"
  22. #include "WorldObject.h"
  23. #include "TextureManager.h"
  24.  
  25. __gc class CFace : public CWorldObject
  26. {
  27. private:
  28.     bool bSpecialTexture;
  29.     
  30.     int iIndex;
  31.     unsigned int iID;
  32.     Vector *vAxisU;
  33.     Vector *vAxisV;
  34.     Vertex2f vShift;
  35.     Vertex2f vScale;
  36.     float fRotation;
  37.     
  38.     int iNumVertices;
  39.  
  40.     Vertex2f *TexCoords;
  41.     Vertex3f *Vertices;
  42.     Vertex3f vNormal;
  43.  
  44. public:
  45.     CFace(CConfig *Config, int iNumVertices) : CWorldObject(Config)
  46.     {
  47.         bSpecialTexture = false;
  48.         this->iNumVertices = iNumVertices;
  49.  
  50.         TexCoords = new Vertex2f[iNumVertices];
  51.         Vertices = new Vertex3f[iNumVertices];
  52.     }
  53.  
  54.     ~CFace()
  55.     {
  56.         delete []TexCoords;
  57.         delete []Vertices;
  58.     }
  59.     
  60.     void SetVertex(int iIndex, Vertex3f Vertex)
  61.     {
  62.         Vertices[iIndex] = Vertex;
  63.     }
  64.  
  65.     void SetNormal(Vertex3f vNormal)
  66.     {
  67.         this->vNormal.X = vNormal.X;
  68.         this->vNormal.Y = vNormal.Y;
  69.         this->vNormal.Z = vNormal.Z;
  70.     }
  71.  
  72.     void SetSpecialTexture(bool bSpecialTexture)
  73.     {
  74.         this->bSpecialTexture = bSpecialTexture;
  75.     }
  76.  
  77.     void SetTextureInfo(int iIndex, Vector *vAxisU, Vector *vAxisV, Vertex2f vShift, Vertex2f vScale, float fRotation)
  78.     {
  79.         this->iIndex = iIndex;
  80.         this->vAxisU = vAxisU;
  81.         this->vAxisV = vAxisV;
  82.         this->vShift.X = vShift.X;
  83.         this->vShift.Y = vShift.Y;
  84.         this->vScale.X = vScale.X;
  85.         this->vScale.Y = vScale.Y;
  86.         this->fRotation = fRotation;
  87.     }
  88.  
  89.     void SetTextureID(unsigned int iID)
  90.     {
  91.         this->iID = iID;
  92.     }
  93.  
  94.     Vertex3f *GetVertices()
  95.     {
  96.         return Vertices;
  97.     }
  98.  
  99.     Vertex3f GetVertex(int iIndex)
  100.     {
  101.         return Vertices[iIndex];
  102.     }
  103.     
  104.     int GetVertexCount()
  105.     {
  106.         return iNumVertices;
  107.     }
  108.  
  109.     String *GetTexture(CTextureManager *TextureManager)
  110.     {
  111.         return TextureManager->GetName(iIndex);
  112.     }
  113.  
  114.     float GetUShift()
  115.     {
  116.         return vShift.X;
  117.     }
  118.  
  119.     float GetVShift()
  120.     {
  121.         return vShift.Y;
  122.     }
  123.  
  124.     float GetUScale()
  125.     {
  126.         return vScale.X;
  127.     }
  128.  
  129.     float GetVScale()
  130.     {
  131.         return vScale.Y;
  132.     }
  133.  
  134.     float GetRotation()
  135.     {
  136.         return fRotation;
  137.     }
  138.  
  139.     void UpdateTexCoords(CTextureManager *TextureManager)
  140.     {
  141.         iID = TextureManager->GetID(iIndex);
  142.  
  143.         float W, H, SX, SY;
  144.         W = 1.0f / (float)TextureManager->GetWidth(iIndex);
  145.         H = 1.0f / (float)TextureManager->GetHeight(iIndex);
  146.         SX = 1.0f / vScale.X;
  147.         SY = 1.0f / vScale.Y;
  148.  
  149.         Vector *V;
  150.         for(int i = 0; i < iNumVertices; i++)
  151.         {
  152.             V = new Vector(Vertices[i]);
  153.  
  154.             TexCoords[i].X = (V->Dot(vAxisU) * W * SX) + (vShift.X * W);
  155.             TexCoords[i].Y = (V->Dot(vAxisV) * H * SY) + (vShift.Y * H);
  156.         }
  157.     }
  158.  
  159.     void DrawFaceTextured()
  160.     {
  161.         if(bSpecialTexture && !Config->bDrawSpecialTextures)
  162.             return;
  163.  
  164.         glBindTexture(GL_TEXTURE_2D, iID);
  165.  
  166.         glBegin(GL_POLYGON);
  167.         glNormal3f(vNormal.X, vNormal.Y, vNormal.Z);
  168.         for(int i = 0; i < iNumVertices; i++)
  169.         {
  170.             glTexCoord2fv(&TexCoords[i].X);
  171.             glVertex3fv(&Vertices[i].X);
  172.         }
  173.         glEnd();
  174.     }
  175.  
  176.     void DrawFaceSolid()
  177.     {
  178.         if(bSpecialTexture && !Config->bDrawSpecialTextures)
  179.             return;
  180.  
  181.         glBegin(GL_POLYGON);
  182.         glNormal3f(vNormal.X, vNormal.Y, vNormal.Z);
  183.         for(int i = 0; i < iNumVertices; i++)
  184.         {
  185.             glVertex3fv(&Vertices[i].X);
  186.         }
  187.         glEnd();
  188.     }
  189.  
  190.     void DrawFaceWireFrame()
  191.     {
  192.         if(bSpecialTexture && !Config->bDrawSpecialTextures)
  193.             return;
  194.  
  195.         glBegin(GL_LINE_LOOP);
  196.         for(int i = 0; i < iNumVertices; i++)
  197.         {
  198.             glVertex3fv(&Vertices[i].X);
  199.         }
  200.         glEnd();
  201.     }
  202.  
  203.     void DrawFacePoints()
  204.     {
  205.         if(bSpecialTexture && !Config->bDrawSpecialTextures)
  206.             return;
  207.  
  208.         glBegin(GL_POINTS);
  209.         for(int i = 0; i < iNumVertices; i++)
  210.         {
  211.             glVertex3fv(&Vertices[i].X);
  212.         }
  213.         glEnd();
  214.     }
  215.  
  216.     void Highlight(bool bPrepared)
  217.     {
  218.         if(!bPrepared)
  219.         {
  220.             PrepareHighlight();
  221.         }
  222.  
  223.         glBegin(GL_LINE_LOOP);
  224.         for(int i = 0; i < iNumVertices; i++)
  225.         {
  226.             glVertex3fv(&Vertices[i].X);
  227.         }
  228.         glEnd();
  229.     }
  230.  
  231.     void Outline()
  232.     {
  233.         if(bSpecialTexture && !Config->bDrawSpecialTextures)
  234.             return;
  235.  
  236.         glBegin(GL_LINE_LOOP);
  237.         for(int i = 0; i < iNumVertices; i++)
  238.         {
  239.             glVertex3fv(&Vertices[i].X);
  240.         }
  241.         glEnd();
  242.     }
  243. };